#!/bin/bash - 
#===============================================================================
#
#          FILE:  ex11-6.sh
# 
#         USAGE:  ./ex11-6.sh 
# 
#   DESCRIPTION:  arrow keypress detect
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: bucunzai (), freecityer@gmail.com
#       COMPANY: FreeCity
#       CREATED: 2011年02月19日 21时42分08秒 CST
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error

# Character codes generated by the arrow keys.
arrowUP=$'\x1b[A'
arrowDOWN=$'\x1b[B'
arrowRIGHT=$'\x1b[C'
arrowLEFT=$'\x1b[D'

echo -n "Press a key..."
read -s -n3 keypress

SUCCESS=0
ERR=65

case "$keypress" in
    $arrowUP )
        echo "Up-arrow key pressed."
        ;;
    $arrowDOWN )
        echo "Down-arrow key pressed."
        ;;
    $arrowRIGHT )
        echo "RIGHT-arrow key pressed."
        ;;
    $arrowLEFT )
        echo "LEFT-arrow key pressed."
        ;;
    * )
        echo "Some other key pressed."
        exit $ERR
        ;;
esac

exit $SUCCESS
